package blaha.genalg.beans;

import java.util.HashMap;
import java.util.Map;

import blaha.genalg.methods.ReadAllProperties;

/**
 * Board with its properties. here are placed points and joinings(edges)
 * 
 * @author uziv
 * 
 */

public class Board {

	// private static final Logger log = Log.getLoggerMoje();

	int y, x;
	int points;
	float circleRadius;
	/**
	 * matrix of joins.0 mean no connection between points, 1 is
	 * connection.Distance is stored here, nor weight.
	 */
	public static NonWeightedEdge[][] matrixOfJoins;

	public static Map<Integer, Point> map = new HashMap<Integer, Point>();

	public int getPoints() {
		return points;
	}

	public void addPoint2Map(Point p) {
		map.put(p.name, p);

	}

	public int getSizeMap() {
		return map.size();
	}



	/**
	 * Input connections for given node
	 * 
	 * @param i
	 *            node
	 * @return input connections for given node
	 */
	public int getInputEdgesLinesInMatrixOfJoin(int i) {
		int cCount = 0;
		for (int k = 0; k < points; k++) {
			if (matrixOfJoins[i][k].isConnected())
				cCount++;
		}

		// log.debug("Count for "+i+" is: "+cCount);

		return cCount;
	}

	/**
	 * Output connections for given node
	 * 
	 * @param i
	 *            node
	 * @return output connections for exact node
	 */
	public int getOutputEdgesColumnsInMatrixOfJoins(int i) {
		int cCount = 0;
		for (int k = 0; k < points; k++) {
			if (matrixOfJoins[k][i].isConnected())
				cCount++;
		}
		return cCount;
	}

	/**
	 * Returns number of connections(output&&input) to exact node
	 * 
	 * @param i
	 *            node
	 * @return number of connections
	 */
	public int getAllConnectionsOfNodeFromMatrixOfJoins(int i) {
		int mcount = 0;
		mcount += getOutputEdgesColumnsInMatrixOfJoins(i);
		mcount += getInputEdgesLinesInMatrixOfJoin(i);
		return mcount;
	}

	/**
	 * Board represent 2D surface, where points are placed
	 * 
	 * @param points
	 * @param circleRadius
	 */
	public Board(ReadAllProperties settings) {
		this.points = settings.points;
		this.circleRadius = settings.radiusCircle;
		matrixOfJoins = new NonWeightedEdge[points][points];
		// inicializace
		for (int i = 0; i < points; i++) {
			for (int j = 0; j < points; j++) {
				matrixOfJoins[i][j] = new NonWeightedEdge();
			}
		}

		map.clear();
		this.x = settings.xBoard;
		this.y = settings.yBoard;

	}

}
